home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / kernserv / lock.h < prev    next >
Text File  |  1995-02-14  |  2KB  |  85 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1989 Carnegie-Mellon University
  4.  * Copyright (c) 1988 Carnegie-Mellon University
  5.  * Copyright (c) 1987 Carnegie-Mellon University
  6.  * All rights reserved.  The CMU software License Agreement specifies
  7.  * the terms and conditions for use and redistribution.
  8.  */
  9. /*
  10.  * HISTORY
  11.  * 11-Jul-91  Gregg Kellogg (gk) at NeXT
  12.  *    Initial version.
  13.  */
  14. /*
  15.  *    File:    kernserv/lock.h
  16.  *    Author:    Avadis Tevanian, Jr., Michael Wayne Young
  17.  *    Copyright (C) 1985, Avadis Tevanian, Jr., Michael Wayne Young
  18.  *
  19.  *    Exported locking primitives definitions
  20.  *
  21.  */
  22.  
  23. #ifndef    _KERN_INTERNAL_LOCK_H_
  24. #define _KERN_INTERNAL_LOCK_H_
  25.  
  26. #import <mach/boolean.h>
  27.  
  28. /*
  29.  *    A simple spin lock.
  30.  */
  31.  
  32. #import    <mach/machine/simple_lock.h>
  33.  
  34. /*
  35.  *    The general lock structure.  Provides for multiple readers,
  36.  *    upgrading from read to write, and sleeping until the lock
  37.  *    can be gained.
  38.  *
  39.  *    On some (many) architectures, assembly language code in the inline
  40.  *    program fiddles the lock structures.  It must be changed in concert
  41.  *    with the structure layout.
  42.  */
  43. struct lock {
  44.     /*    Only the "interlock" field is used for hardware exclusion;
  45.      *    other fields are modified with normal instructions after
  46.      *    acquiring the interlock bit.
  47.      */
  48.     simple_lock_data_t    interlock;
  49.     unsigned int    read_count:16,
  50.             want_upgrade:1,
  51.             want_write:1,
  52.             waiting:1,
  53.             can_sleep:1,
  54.             recursion_depth:12;
  55.     char        *thread;
  56.         /* Thread that has lock, if recursive locking allowed */
  57.         /* (Not thread_t to avoid recursive definitions.) */
  58. };
  59.  
  60. typedef struct lock    lock_data_t;
  61. typedef struct lock    *lock_t;
  62.  
  63. /* Sleep locks must work even if no multiprocessing */
  64.  
  65. extern lock_t        lock_alloc();
  66. extern void        lock_free();
  67. extern void        lock_init();
  68. extern void        lock_sleepable();
  69. extern void        lock_write();
  70. extern void        lock_read();
  71. extern void        lock_done();
  72. extern boolean_t    lock_read_to_write();
  73. extern void        lock_write_to_read();
  74. extern boolean_t    lock_try_write();
  75. extern boolean_t    lock_try_read();
  76. extern boolean_t    lock_try_read_to_write();
  77.  
  78. #define lock_read_done(l)    lock_done(l)
  79. #define lock_write_done(l)    lock_done(l)
  80.  
  81. extern void        lock_set_recursive();
  82. extern void        lock_clear_recursive();
  83.  
  84. #endif    _KERN_INTERNAL_LOCK_H_
  85.